import { IResponse } from '@/types/data'
import { BannerItem,GoodsNew,GoodsHot } from '@/types/good'
import request from '@/utils/request'
import { defineStore } from 'pinia'

export default defineStore('home', {
    state: () => ({
        bannerList: [] as BannerItem[], //轮播图
        newGoodsList: [] as GoodsNew[],//新鲜好物
        hotGoodsList:[] as GoodsHot[] //人气推荐
    }),
    actions: {
        // 轮播图
        async getBannerList() {
            const res = await request.get<IResponse<BannerItem[]>>('/home/banner')
            this.bannerList = res.data.result
        },
        // 新鲜好物列表
        async getGoodsNewList() {
          const res = await request.get<IResponse<GoodsNew[]>>('/home/new')
          this.newGoodsList = res.data.result
        },
        // 获取人气推荐列表
        async getGoddsHotList() {
          const res = await request.get<IResponse<GoodsHot[]>>('/home/hot')
          this.hotGoodsList = res.data.result
          console.log('getGoddsHotList',res)
          
        }
    },
})